﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Event_SG_EWDT
{
    public partial class User : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
            if (Session["Member"] == null)
            {
                topUsertest.Visible = true;
                DivUserSignout.Visible = false;
                topUserUsers.Visible = false;
            }
            else
            {
                topUsertest.Visible = false;
                DivUserSignout.Visible = true;
                topUserUsers.Visible = true;

                int unreadMsg = NotificationControl.NoOfUnreadMessage(Session["Member"].ToString());

                if (unreadMsg > 0)
                {
                    string msg = "$().toastmessage('showNoticeToast', 'Hey! You have {0} unread notification{1}!');";

                    if (unreadMsg == 1)
                    {
                        msg = String.Format(msg, unreadMsg, "");
                    }
                    else
                    {
                        msg = String.Format(msg, unreadMsg, "s");
                    }

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toast", msg, true);
                }
            }
            //}
        }

        protected void btnHeaderUserSignin_Click(object sender, EventArgs e)
        {
            Member m = (MemberControls.VerifyAccount(tbxUserHeaderEmail.Text, tbxUserHeaderPassword.Text));
            if (m!= null)
            {
                Session["Member"] = m.MembershipNo;
                Response.Redirect("~/index.aspx");
            }
        }

        protected void btnUserSignout_Click(object sender, EventArgs e)
        {
            Session["Member"] = null;

            Session.Abandon();

            Response.Redirect("~/index.aspx");
        }

        protected void btnUserHeaderSignup_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/registration.aspx");
        }
    }
}